package com.yanfan.data.service.impl;

import com.yanfan.common.utils.DateUtils;
import com.yanfan.data.domain.SnmpResponse;
import com.yanfan.data.mapper.SnmpResponseMapper;
import com.yanfan.data.service.ISnmpResponseService;
import com.yanfan.data.tdengine.service.TDSnmpResponseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * snmp响应结果Service业务层处理
 *
 * @author kerwincui
 * @date 2024-07-28
 */
@Service
public class SnmpResponseServiceImpl implements ISnmpResponseService {
    @Autowired
    private SnmpResponseMapper snmpResponseMapper;

    @Value("${spring.datasource.druid.tdengine-server.enabled}")
    private Boolean enabled;

    @Autowired
    private TDSnmpResponseService tdSnmpResponseService;


    /**
     * 查询snmp响应结果
     *
     * @param id snmp响应结果主键
     * @return snmp响应结果
     */
    @Override
    public SnmpResponse selectSnmpResponseById(Long id) {
        if (enabled) {
            return tdSnmpResponseService.selectSnmpResponseById(id);
        }
        return snmpResponseMapper.selectSnmpResponseById(id);
    }

    /**
     * 查询snmp响应结果列表
     *
     * @param snmpResponse snmp响应结果
     * @return snmp响应结果
     */
    @Override
    public List<SnmpResponse> selectSnmpResponseList(SnmpResponse snmpResponse) {
        if (enabled) {
            return tdSnmpResponseService.TDSelect(snmpResponse);
        }
        return snmpResponseMapper.selectSnmpResponseList(snmpResponse);
    }

    /**
     * 新增snmp响应结果
     *
     * @param snmpResponse snmp响应结果
     * @return 结果
     */
    @Override
    public int insertSnmpResponse(SnmpResponse snmpResponse) {
        snmpResponse.setCreateTime(DateUtils.getNowDate());
        return snmpResponseMapper.insertSnmpResponse(snmpResponse);
    }

    /**
     * 修改snmp响应结果
     *
     * @param snmpResponse snmp响应结果
     * @return 结果
     */
    @Override
    public int updateSnmpResponse(SnmpResponse snmpResponse) {
        return snmpResponseMapper.updateSnmpResponse(snmpResponse);
    }

    /**
     * 批量删除snmp响应结果
     *
     * @param ids 需要删除的snmp响应结果主键
     * @return 结果
     */
    @Override
    public int deleteSnmpResponseByIds(Long[] ids) {
        return snmpResponseMapper.deleteSnmpResponseByIds(ids);
    }

    /**
     * 删除snmp响应结果信息
     *
     * @param id snmp响应结果主键
     * @return 结果
     */
    @Override
    public int deleteSnmpResponseById(Long id) {
        return snmpResponseMapper.deleteSnmpResponseById(id);
    }
}
